package design_4_builder.demo1.builder;

import java.util.Arrays;

public class StringBuffer extends AbstractStringBuilder {

	public StringBuffer() {
		super(16);
	}

	public StringBuffer(int capacity) {
		super(capacity);
	}


	@Override
	public StringBuffer append(String str) {
		super.append(str);
		return this;
	}

	@Override
	public StringBuffer append(char str) {
		super.append(str);
		return this;
	}

	@Override
	public StringBuffer append(boolean b) {
		super.append(b);
		return this;
	}


	//
	private transient char[] toStringCache;

	@Override
	public String toString() {
		if (toStringCache == null) {
			toStringCache = Arrays.copyOfRange(value, 0, count);
		}
		return new String(toStringCache);
	}
}
